import java.util.Stack;

public class MinStack {
    //最小栈
    //需要两个栈作为辅助站
    Stack<Integer> stack;
    Stack<Integer> minstack;
    public MinStack() {
       stack  = new Stack();
       minstack = new Stack<>();
    }
    //放入元素
    public void push(int val) {
        stack.push(val);
        if(minstack.isEmpty()) {
            minstack.push(val);
        }else {
            int peekNum = minstack.peek();
            if(val<peekNum) {
                minstack.push(val);
            }
        }
    }
    //弹出元素
    public void pop() {
        int val = stack.pop();
        if(val == minstack.peek()) {
            minstack.pop();
        }
    }
    //拿到栈顶元素
    public int top() {
        return stack.peek();
    }
    //拿到最小元素
    public int getMin() {
        return minstack.peek();
    }
}
